//插件后台专用js
window.daicuo.navs = {
    //监听筛选事件
    onChange: function(){
        $(document).on("change", '#nav_type', function(){
            daicuo.navs.showAddon($(this).val());
        });
    },
    //data-events 点击事件
    events: {
        'click [data-toggle="edit"]': function (event, value, row, index) {
            $(event.currentTarget).attr('data-callback','daicuo.navs.dialog');
        }
    },
    //data-formatter 表格列格式器
    formatter: function(value, row, index, field){
        //var $url = daicuo.config.file + '/' + daicuo.config.controll + '/' + daicuo.config.action + '/?'+ field +'='+value;
        var $url = daicuo.config.file+daicuo.config.root+'addon/index/?module=navs&controll=admin&action=index&'+ field +'='+value;
        return '<a class="text-purple" href="'+$url+'">'+value+'</a>';
    },
    //表格列格式器 管理操作字段
    operate: function(value, row, index, field){
        var urlPreview = daicuo.config.file+daicuo.config.root+'addon/index/?module=navs&controll=admin&action=preview&id='+row.op_id;
        var urlEdit    = daicuo.config.file+daicuo.config.root+'addon/index/?module=navs&controll=admin&action=edit&id='+row.op_id;
        var urlDelete  = daicuo.config.file+daicuo.config.root+'addon/index/?module=navs&controll=admin&action=delete&id='+row.op_id;
        var array = new Array(); 
        array.push('<div class="btn-group btn-group-sm">');
        array.push('<a class="btn btn-outline-secondary" href="'+urlPreview+'" data-toggle="preview" target="_blank"><i class="fa fa-fw fa-link"></i></a>');
        array.push('<a class="btn btn-outline-secondary" href="'+urlEdit+'" data-toggle="edit" data-modal-xl="1"><i class="fa fa-fw fa-pencil"></i></a>');
        array.push('<a class="btn btn-outline-secondary" href="'+urlDelete+'" data-toggle="delete"><i class="fa fa-fw fa-trash-o"></i></a>');
        array.push('</div>');
        return array.join('');
    },
    //编辑按钮回调方法
    dialog: function($data, $status, $xhr) {
        daicuo.bootstrap.dialogForm($data);//展示表单数据
        daicuo.navs.showAddon($('.dc-modal #nav_type').val());//刷新是否显示插件内部链接
    },
    //是否显示插件内部导航方法
    showAddon: function($value){
        if($value == 'addon'){
            $('.dc-modal #nav_url').parents('.form-group').addClass('d-none');
            $('.dc-modal #nav_module').parents('.form-group').removeClass('d-none');
            $('.dc-modal #nav_controll').parents('.form-group').removeClass('d-none');
            $('.dc-modal #nav_action').parents('.form-group').removeClass('d-none');
            $('.dc-modal #nav_params').parents('.form-group').removeClass('d-none');
            $('.dc-modal #nav_suffix').parents('.form-group').removeClass('d-none');
        }else{
            $('.dc-modal #nav_url').parents('.form-group').removeClass('d-none');
            $('.dc-modal #nav_module').parents('.form-group').toggleClass('d-none',true);
            $('.dc-modal #nav_controll').parents('.form-group').toggleClass('d-none',true);
            $('.dc-modal #nav_action').parents('.form-group').toggleClass('d-none',true);
            $('.dc-modal #nav_params').parents('.form-group').toggleClass('d-none',true);
            $('.dc-modal #nav_suffix').parents('.form-group').toggleClass('d-none',true);
        }
    }
};

//jquery
$(function() {
    window.daicuo.navs.onChange();
});